var table;
var layer;
var laydate;
layui.use(['layer','table','laydate'],function(){
    table=layui.table;
    layer=layui.layer;
    laydate = layui.laydate;

    laydate.render({
        elem: '#createDate', //指定元素
        type: 'date',
        trigger: 'click' //时间时间为点击事件
    });
    //获取路由跳转过来的商品id
    var idArray = window.location.search.split("?");
    var logId = idArray[1];
    selProductLog(logId);

    //重置按钮
    $('#resetBtn').on('click',function(){
        selProductLog(logId);
    })

});

//页面搜索框
var seek=function(){
    var productCode=$('input[name=productCode]').val();
    var productName=$('input[name=productName]').val();
    var createDate=$('input[name=createDate]').val();
    $.post("/SyOperationController/selProductLog",
        {"productCode":productCode,"productName":productName,"createDate":createDate,"type":3,},
        function (data) {
            getTable(data.data);
        }
    );
}
//获取商品日志
function selProductLog(logId) {
    $.ajax({
        url: "/SyOperationController/selProductLog",
        type: "post",
        dataType: "json",
        data:{"type":3,"logId":logId},
        success: function (data) {
            getTable(data.data);
        }
    });
}

//获取商品日志赋值给table
function getTable(data){
    var tb1=table.render({
        elem:"#table_id",
        data:data,
        title:"商品日志",
        limit:10,
        toolbar:"#toolbar_id",
        page:true,
        cols:[[
            //{type:'checkbox',align:'center',width:50},//复选框靠左
            {title:'序号',align:'center',width:60,templet:function(data){
                    return data.LAY_INDEX;
                }},
            {field:'product_code',title:'商品编号',align:'center'},
            {field:'product_name',title:'商品名称',align:'center'},
            {field:'price',title:'原价',align:'center'},
            {field:'nprice',title:'现价',align:'center'},
            {field:'state',title:'上下架',align:"center",templet:function(data){
                    if(data.state==1){
                        return "上架中";
                    }else{
                        return "已下架";
                    }
                }},
            {field:'true_name',title:'操作人员',align:'center'},
            {field:'create_date',title:'操作时间',align:"center",templet:function(d){
                    var date=d.create_date;
                    date = date.slice(0, date.indexOf("."));
                    date = date.replaceAll('T',' ');
                    return  date;
                }}
        ]]
    });
}

//刷新
function refresh() {
    location.reload();
};